﻿using System;
using GameFramework.Battle.Core;
using UnityEditor;
using UnityEngine;
using Yoozoo.Gameplay.RTS;
using Yoozoo.Gameplay.RTS.Proto;
using Yoozoo.Mars.Got.SpriteAnim;

namespace WorldMap.DynamicLayer.MarchLayer.Editor
{
    [CustomEditor(typeof(MarchMono))]
    public class MarchMonoEditor : UnityEditor.Editor
    {
        private MarchMono _mono;
        private MarchEntity _entity;
        private MarchInfo _marchInfo;
        private MarchSquare _square;
        
        private int toolbarOption = 0;
        private string[] toolbarTexts = { "基础", "头像"};
        public override void OnInspectorGUI()
        {
            
            base.OnInspectorGUI();
            _mono = this.target as MarchMono;
            if (!_mono.enabled)
            {
                return;
            }
            _entity = ArmyManager.Instance.MarchManager.GetMarchEntityByIdAndType(_mono.marchId,_mono.TargetCoordinateType);
            if (_entity == null)
            {
                return;
            }
            _marchInfo = _entity.MarchInfo;
            _square = _entity.GetBattleSquare();
            
            toolbarOption = GUILayout.Toolbar(toolbarOption, toolbarTexts);

            switch (toolbarOption)
            {
                case 0:
                    ShowBasicInfo(_entity,_marchInfo,_square);
                    break;
                case 1:
                    ShowHeadInfo(_entity,_marchInfo,_square);
                    break;
                default:
                    break;
            }


        }

        private void ShowHeadInfo(MarchEntity _entity, MarchInfo _marchInfo, MarchSquare _marchSquare)
        {
            if (_entity!=null && _entity.Hud!=null)
            {
                _entity.Hud.OnInspector();
                /*EditorGUILayout.LabelField("Selected", _entity.Hud.IsSelected.ToString());
                EditorGUILayout.LabelField("ForceShowHud", _entity.Hud.ForceShowHud.ToString());

                EditorGUILayout.LabelField("IsAttackSelf", _entity.Hud.IsAttackSelf.ToString());
                EditorGUILayout.LabelField("IsSelfAttacked", _entity.Hud.IsSelfAttacked.ToString());
                EditorGUILayout.LabelField("IsSelfAttacking", _entity.Hud.IsSelfAttacking.ToString());
                EditorGUILayout.LabelField("isPlayingDeadHudAni", _entity.Hud.isPlayingDeadHudAni.ToString());
                EditorGUILayout.LabelField("isPlayedDeadHudAni", _entity.Hud.isPlayedDeadHudAni.ToString());
                EditorGUILayout.LabelField("_hudReturnNormalStyleStartTime", _entity.Hud._hudReturnNormalStyleStartTime.ToString());
                EditorGUILayout.LabelField("_isBattleStyleHud", _entity.Hud._isBattleStyleHud.ToString());*/
            }
        }
        
        private void ShowBasicInfo(MarchEntity _entity, MarchInfo _marchInfo, MarchSquare _marchSquare)
        {
                        
            //夹击数据
            
            MarchBesiegeManager.Instance.ShowTargetDataInspector(_mono.marchId,_mono.TargetCoordinateType);
            
            //部队的状态
            EditorGUILayout.LabelField("部队的状态:");
            EditorGUILayout.BeginVertical();
            EditorGUILayout.LabelField("Team",_marchInfo.Team.ToString());
            EditorGUILayout.LabelField("LineId",_entity.LineId.ToString());
            if (_entity.RtsServerInfo!=null)
            {
                EditorGUILayout.LabelField("NpcType", _entity.RtsServerInfo.npcType.ToString());
                EditorGUILayout.LabelField("DefenceTroop", _entity.RtsServerInfo.DefenceTroop.ToString());
            }
            if (_marchInfo.TargetId != 0)
            {
                EditorGUILayout.LabelField("TargetId",_marchInfo.TargetId.ToString());
            }
            if (_marchInfo.BattleTargetId!=0)
            {
                EditorGUILayout.LabelField("BattleTargetID", _marchInfo.BattleTargetId.ToString());
                var target =
                    MarchManager.Instance.GetMarchEntityByIdAndType(_marchInfo.BattleTargetId,
                        _marchInfo.attackTargetType);
                if (target != null)
                {
                    EditorGUILayout.LabelField("BattleTargetPosition", target.Position.ToString());
                    EditorGUILayout.LabelField("BattleTargetName", target.Mono.name);
                }
                
            }
            if (_marchInfo.attackTargetType!=0)
            {
                EditorGUILayout.LabelField("attackTargetType", _marchInfo.attackTargetType.ToString());
            }
            EditorGUILayout.LabelField("Speed", _marchInfo.Speed.ToString());
            
            EditorGUILayout.LabelField("ServerInBattle", _marchInfo.ServerInbattle.ToString());
            EditorGUILayout.LabelField("ClientInBattle", _marchInfo.IsClientInBattle.ToString());

            EditorGUILayout.LabelField("SoldierCount",_marchInfo.SoldierCount.ToString());
            EditorGUILayout.LabelField("InitSoldierCount",_marchInfo.InitSoldierCount.ToString());
            EditorGUILayout.LabelField("ClientMarchStatue", Enum.GetName(typeof(EMarchStatus),_marchInfo.ClientMarchStatue));
            EditorGUILayout.LabelField("MarchType", Enum.GetName(typeof(MarchType),_marchInfo.MarchType));
            EditorGUILayout.LabelField("MarchStatus", Enum.GetName(typeof(MarchStatus), _marchInfo.MarchStatus));
            EditorGUILayout.LabelField("AssemblyLeader", _entity.RtsServerInfo.isAssemblyLeader.ToString());
            EditorGUILayout.LabelField("IsFakeParent", _entity.isFakeParent.ToString());
            EditorGUILayout.Vector3Field("CurrentForward",_marchInfo.CurrentForward);
            EditorGUILayout.Vector3Field("CurrentPos",_marchInfo.Position);
            EditorGUILayout.Vector3Field("EndPosition",_marchInfo.EndPosition);

            EditorGUILayout.LabelField("InitSoldierCount", _marchInfo.InitSoldierCount.ToString());

            EditorGUILayout.EndVertical();
        }
    }
}